package com.jarvis.zeng.design.pattern.decorator.promotion;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 执行类
 * @author zengjun
 */
public class Main {

    public static void main(String[] args) {

        Order order = new Order();
        init(order);
        for(OrderDetail orderDetail : order.getList()){
            BigDecimal payMoney = PromotionFactory.getPayMoney(orderDetail);
            orderDetail.setPayMoney(payMoney);
            System.out.println("最终支付金额：" +  orderDetail.getPayMoney());
        }
    }

    /**
     *初始化订单
     */
    private static Order init(Order order) {
        // 促销集合
        Map<PromotionType, SupportPromotions> supportProjectionist = new HashMap<>(8);

        // 优惠券促销
        UserCoupon userCoupon= new UserCoupon();
        userCoupon.setCoupon(new BigDecimal(3));
        userCoupon.setSku("aaa1111");
        userCoupon.setUserId(11);
        SupportPromotions supportPromotions = new SupportPromotions();
        supportPromotions.setPromotionType(PromotionType.COUPON);
        supportPromotions.setPriority(1);
        supportPromotions.setUserCoupon(userCoupon);
        supportProjectionist.put(PromotionType.COUPON, supportPromotions);


        // 红包促销
        UserRedPacket userRedPacket= new UserRedPacket();
        userRedPacket.setId(1);
        userRedPacket.setRedPacket(new BigDecimal(10));
        userRedPacket.setSku("aaa1111");
        userCoupon.setUserId(11);
        SupportPromotions supportPromotions1 = supportPromotions.clone();
        supportPromotions1.setPromotionType(PromotionType.REDPACKET);
        supportPromotions1.setPriority(2);
        supportPromotions1.setUserRedPacket(userRedPacket);
        supportProjectionist.put(PromotionType.REDPACKET, supportPromotions1);

        Merchandise merchandise = new Merchandise();
        merchandise.setSku("aaa1111");
        merchandise.setName("苹果");
        merchandise.setPrice(new BigDecimal(20));
        merchandise.setSupportPromotions(supportProjectionist);

        List<OrderDetail> orderDetailList = new ArrayList<OrderDetail>();

        OrderDetail orderDetail = new OrderDetail();
        orderDetail.setId(1);
        orderDetail.setOrderId(1111);
        orderDetail.setMerchandise(merchandise);

        orderDetailList.add(orderDetail);

        order.setList(orderDetailList);

        return order;

    }
}